rm(list=ls(all.names=TRUE))
set.seed(221269)


#### Loading data 
library(ggplot2)


#### Plot latent means
## I manually entered the latent means and 
## their standard errors (for Blacks). 
means <- data.frame(matrix(NA, nrow=6, ncol=3))
colnames(means) <- c("year", "mean", "se")
means[1,] <- c("1992", 1.296, 0.198)
means[2,] <- c("2000", 1.083, 0.244)
means[3,] <- c("2004", 1.020, 0.207)
means[4,] <- c("2008", 0.788, 0.107)
means[5,] <- c("2012", 1.153, 0.213)
means[6,] <- c("2016", 1.053, 0.275)
# Converting column types to the appropriate class
means[,1] <- as.character(means[,1])
means[,2] <- as.numeric(means[,2])
means[,3] <- as.numeric(means[,3])

## Plot
means_plot <- 
  ggplot(means, aes(x=year, y=mean)) +
  geom_hline(yintercept = c(0, 0.5, 1.0, 1.5),
             linetype = "solid",
             colour = "gray90",
             linewidth =0.35) +
  geom_point(color="black", size=2) + 
  geom_errorbar(aes(ymax=mean+1.96*se,
                    ymin=mean-1.96*se,
                    width=0.05)) +
  scale_y_continuous(breaks=c(0,+0.5,+1,+1.5),
                     labels=c('0','+0.5','+1','+1.5'),
                     limits=c(0,1.75) ) + 
  labs(x="Year", y="Latent mean (95% confidence interval)") +
  theme(
    legend.position    ="none",
    panel.border       =element_rect(colour="black", linetype="solid", fill="NA", linewidth=1),
    panel.background   =element_rect(fill="transparent"),
    axis.text.x        =element_text(colour="black",size=11),
    axis.text.y        =element_text(colour="black",size=11),
    axis.title.x       =element_text(colour="black",size=10),
    axis.title.y       =element_text(colour="black",size=10),
    axis.ticks.x       =element_blank(), 
    axis.ticks.y       =element_line(colour="black")
  )
means_plot

pdf(file="figure1.pdf", width=6, height=4)
means_plot
dev.off()

png("figure1.png", units="in", width=6, height=4, res=1200)
means_plot
dev.off()
